<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\OSS;

class CommonController extends Controller
{
    //通讯录
    public function OssUpload(Request $request)
    {

        //获取上传的文件
        $file = $request->file('file');

        //获取上传图片的临时地址
        $tmppath = $file->getRealPath();

        //生成文件名

        $fileName = rand(1000,9999) . $file->getFilename() . time() .date('ymd') . '.' . $file->getClientOriginalExtension();

        //拼接上传的文件夹路径(按照日期格式1810/17/xxxx.jpg)
        $pathName = date('Y-m/d').'/'.$fileName;

        //上传图片到阿里云OSS
        OSS::publicUpload('guanchi', $pathName, $tmppath, ['ContentType' => $file->getClientMimeType()]);

        //获取上传图片的Url链接
        $data['img'] = OSS::getPublicObjectURL('guanchi', $pathName);

        return response()->json(['code'=>'200','msg' => '提交成功','data'=>$data]);

    }
}
